@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">




<ul class="list-unstyled booklist">


		<li class="media">
		    <a href="{{ route('books.edit',['book'=>$book->id]) }}"><img class="mr-3" src="{{ $book->cover }}" style="width:100px;" alt="Generic placeholder image"></a>
		    <div class="media-body">
		      <h5 class="mt-0 mb-1"><a href="{{ route('books.edit',['book'=>$book->id]) }}">{{ $book->name }} </a><span>作者：<i>{{ $book->user->name }}</i></span></h5>
		      {{ $book->description }}
		    </div>
		</li>        
		
	  		
  		
</ul>

@if ($book->chapters && count($book->chapters)>0)
<nav class="col-md-2 d-none d-md-block bg-light sidebar">
          <div class="sidebar-sticky">
            <ul class="nav flex-column">
        @foreach ($book->chapters as $chapter)
            <li class="nav-item"><a class="nav-link @if ($chapter->id == $current_chapter->id) hover @endif" href="{{ route('book_chapter.edit',['chapter'=>$chapter->id]) }}"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file"><path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"></path><polyline points="13 2 13 9 20 9"></polyline></svg>{{ $chapter->name }}</a></li>
            <h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mb-1 text-muted">
              <span></span>
              <a class="d-flex align-items-center text-muted" href="{{ route('posts.create',['chapter'=>$chapter->id]) }}">
                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-plus-circle"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="16"></line><line x1="8" y1="12" x2="16" y2="12"></line></svg>
              </a>
            </h6>

            @if ($chapter->posts && count($chapter->posts)>0)
                <ul class="nav flex-column mb-2 ml10">              
                @foreach ($chapter->posts as $post_item)
                    <li class="nav-item"><a class="nav-link" href="{{ route('posts.edit',['chapter'=>$chapter->id,'post'=>$post_item->id]) }}"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file-text"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>{{ $post_item->name }}</a></li>
                @endforeach
                </ul>
            @endif

            
        @endforeach
    </ul>
</div>
</nav>
@endif

<div class="col-md-8">
<div class="card">
                <div class="card-header">{{ __('Edit Chapter') }}</div>

                <div class="card-body">
                    <form method="POST" action="{{ route('book_chapter.update',['chapter'=>$current_chapter->id]) }}">
                        @csrf
                        @method('PUT')
                        <div class="form-group row">
                            <label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>

                            <div class="col-md-6">
                                <input id="name" type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" value="{{ $current_chapter->name }}" required autofocus>

                                @if ($errors->has('name'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('name') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row mb-0">
                            <div class="col-md-6 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    {{ __('Update') }}
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
</div>




    </div>
</div>
@endsection
